package org.bigk.invoices.model;

import java.io.Serializable;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.bigk.invoices.utils.TextUtils;

@Entity
@Table(name = "purchasers")
public class Purchaser extends PaginatedBean implements Serializable {

	private static final long serialVersionUID = 1548460555302521767L;
	

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Long id;

	@Column(name = "name")
	private String name;

	@Column(name = "address")
	private String address;

	@Column(name = "nip")
	private String nip;

	public Purchaser() {
	}

	public String toString() {
		return new ToStringBuilder(this)
				.append("id", id)
				.append("name", name)
				.append("address", address)
				.append("nip", nip)
				.toString();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) return false;
		if (obj == this) return true;
		if (Purchaser.class.isAssignableFrom(obj.getClass())) {
			final Purchaser other = Purchaser.class.cast(obj);
			return new EqualsBuilder().append(this.id, other.id)
					.append(this.name, other.name)
					.append(this.address, other.address)
					.append(this.nip, other.nip).isEquals();
	    }
	    return false;
	}
	
	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(this.id)
				.append(this.name)
				.append(this.address)
				.append(this.nip)
				.hashCode();
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getNip() {
		return nip;
	}

	public void setNip(String nip) {
		this.nip = nip;
	}
	
	public String getNameHTML() {
		return TextUtils.convert2HtmlText(name);
	}

	public String getAddressHTML() {
		return TextUtils.convert2HtmlText(address);
	}

	public String getNameJS() {
		return TextUtils.convert2JsText(name);
	}

	public String getAddressJS() {
		return TextUtils.convert2JsText(address);
	}

	public String getNipJS() {
		return TextUtils.convert2JsText(nip);
	}

}
